/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameObject;

import FrameWork.Models.GLModel;
import java.util.ArrayList;
import utils.POINT;
import utils.Vector3;

/**
 *
 * @author QuyNguyenNam
 */
public class SoldierPiece extends ChessPiece {

    public SoldierPiece(GLModel md, Vector3 pos) {
        super(md, pos);
    }

    public SoldierPiece(GLModel md, POINT point) {
        super(md, point);
    }

    public SoldierPiece(int nameID, POINT point) {
        super(nameID, point);
    }
    
    @Override
    public ArrayList<POINT> getListCanGo(int[][] map) {
        ArrayList<POINT> result = new ArrayList<POINT>();
        POINT tmpPOINT = null;

        // check trai
        if (canMoveLeft(map)) {
            tmpPOINT = new POINT(point.x, point.y - 1);
            if (isEmptyLocation(map, tmpPOINT)) {
                result.add(tmpPOINT);   
            } else {
                if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                    if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                        result.add(tmpPOINT);
                    }
                }
            }
        }

        // check tren
        if (canMoveUp(map)) {
            tmpPOINT = new POINT(point.x - 1, point.y);
            if (isEmptyLocation(map, tmpPOINT)) {
                result.add(tmpPOINT);   
            } else {
                if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                    if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                        result.add(tmpPOINT);
                    }
                }
            }
        }

        // check phai
        if (canMoveRight(map)) {
            tmpPOINT = new POINT(point.x, point.y + 1);
            if (isEmptyLocation(map, tmpPOINT)) {
                result.add(tmpPOINT);   
            } else {
                if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                    if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                        result.add(tmpPOINT);
                    }
                }
            }
        }

        // check duoi
        if (canMoveDown(map)) {
            tmpPOINT = new POINT(point.x + 1, point.y);
            if (isEmptyLocation(map, tmpPOINT)) {
                result.add(tmpPOINT);   
            } else {
                if (!(tmpPOINT.x < 1 || tmpPOINT.x > 10 || tmpPOINT.y < 1 || tmpPOINT.y > 9)) {
                    if (isOpponent(nameID, map[tmpPOINT.x][tmpPOINT.y])) {
                        result.add(tmpPOINT);
                    }
                }
            }
        }

        return result;
    }

    @Override
    public boolean canMoveLeft(int[][] map) {
        if (point.y == 1) {
            return false;
        } else if (nameID < 16 && point.x <= 5) {
            return false;
        } else if (nameID >= 16 && point.x > 5) {
            return false;
        }

        return true;
    }

    @Override
    public boolean canMoveUp(int[][] map) {
        if (nameID < 16) {
            return false;
        }

        return true;
    }

    @Override
    public boolean canMoveRight(int[][] map) {
        if (point.y == 9) {
            return false;
        } else if (nameID < 16 && point.x <= 5) {
            return false;
        } else if (nameID >= 16 && point.x > 5) {
            return false;
        }

        return true;
    }

    @Override
    public boolean canMoveDown(int[][] map) {
        if (nameID > 16) {
            return false;
        }

        return true;
    }
}
